<?php
class pemilihan_adik_asuh extends MY_Controller{
    function pemilihan_adik_asuh(){
        parent::MY_Controller();
        $this->data['title'] = "Pemilihan Adik Asuh";
        $this->load->model('m_calon_adik_asuh');
        $this->load->model('m_kriteria');
        $this->load->model('m_tingkat_kepentingan_kriteria');
        $this->load->model('m_pemilihan_adik_asuh');
    }
    
    var $data;
    
    function index(){
        $this->data['content'] = 'pemilihan_adik_asuh/v_pemilihan_adik_asuh';
        $this->data['subLink'] = 'pemilihan_adik_asuh/pilih_kriteria';
        $this->data['formTitle'] = 'Form Pemilihan Alternatif';
        $this->data['formView'] = 'pemilihan_adik_asuh/pilih_alternatif';
        $this->data['alternatif'] = $this->m_calon_adik_asuh->getListCalonAdikAsuh();
        
        $this->render($this->data);
    }
    function pilih_kriteria(){
        $this->data['content'] = 'pemilihan_adik_asuh/v_pemilihan_adik_asuh';
        $this->data['subLink'] = 'pemilihan_adik_asuh/matrik_keputusan';
        $this->data['formTitle'] = 'Form Pemilihan Dan Pembobotan Kriteria';
        $this->data['formView'] = 'pemilihan_adik_asuh/pilih_kriteria';
        $this->data['kriteria'] = $this->m_kriteria->getListKriteria();
        $this->data['tingkatKepentinganKriteria'] = $this->m_tingkat_kepentingan_kriteria->getListTingkatKepentinganKriteria();
        $alternatif = $this->input->post('id');
        $nama = $this->input->post('nama');
        $no = 0;
        foreach ($alternatif as $row){
            $alt['alternatif']['id'][] = $row;
            $alt['alternatif']['nama'][] = $nama[$no];
            $no++;
        }
        $this->session->set_userdata($alt);
        
        $this->render($this->data);
    }
    function matrik_keputusan(){
        $this->data['content'] = 'pemilihan_adik_asuh/v_pemilihan_adik_asuh';
        $this->data['subLink'] = 'pemilihan_adik_asuh/pemilihan_adik_asuh_proses';
        $this->data['formTitle'] = 'Form Matrik Keputusan';
        $this->data['formView'] = 'pemilihan_adik_asuh/matrik_keputusan';
        $kriteria = $this->input->post('id');
        $jenis = $this->input->post('jenis');
        $nama = $this->input->post('nama');
        $bobot = $this->input->post('bobot');
        $nilai_bobot = $this->input->post('nilai_bobot');
        
        $i = 0;
        foreach ($kriteria as $row){
            $kri['kriteria']['id'][] = $row;
            $kri['kriteria']['jenis'][] = $jenis[$i];
            $kri['kriteria']['nama'][] = $nama[$i];
            $i++;
        }
        $j = 0;
        foreach ($bobot as $rows){
            $bobot['bobot']['id'][] = $rows;
            $bobot['bobot']['nilai_bobot'][] = $nilai_bobot[$j];
            $j++;
        }
        $this->session->set_userdata($kri);
        $this->session->set_userdata($bobot);
        
        $this->render($this->data);
    }
    function pemilihan_adik_asuh_proses(){
        $insert = $this->m_pemilihan_adik_asuh->pemilihanAdikAsuhProses($this->input->post('data'));
        $this->session->set_flashdata("message",7);
        redirect("pemilihan_adik_asuh/hasil_pemilihan/$insert");
    }
    function hasil_pemilihan($id){
        $this->data['content'] = 'pemilihan_adik_asuh/v_pemilihan_adik_asuh';
        $this->data['formTitle'] = 'Detail Perangkingan Calon Adik Asuh';
        $this->data['formView'] = 'pemilihan_adik_asuh/hasil_pemilihan';
        $this->data['alternatif'] = $this->m_pemilihan_adik_asuh->getAlternatif($id);
        $this->data['kriteria'] = $this->m_pemilihan_adik_asuh->getKriteria($id);
        $this->data['bobot'] = $this->m_pemilihan_adik_asuh->getBobot($id);
        $this->data['matrikKeputusan'] = $this->m_pemilihan_adik_asuh->getMatrikKeputusan($id);
        $this->data['hasilPemilihanAdikAsuh'] = $this->m_pemilihan_adik_asuh->getListHasilPemilihan($id);
        
        $this->render($this->data);
    }
    function hapus_session(){
        $this->session->unset_userdata('alternatif');
        $this->session->unset_userdata('kriteria');
        $this->session->unset_userdata('bobot');
        
        redirect('pemilihan_adik_asuh');
    }
    function pilih_adik_asuh($id_calon_adik_asuh,$periode){
        $update = $this->m_pemilihan_adik_asuh->pilih_adik_asuh($id_calon_adik_asuh);
        if($update == TRUE){
            $this->session->set_flashdata("message",1);
        }else{
            $this->session->set_flashdata("message",2);
        }
        redirect("hasil_pemilihan_adik_asuh/detail_pemilihan_adik_asuh/$periode");
    }
}
?>
